<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GonzalesToolsEntertainmentForGift.aspx.cs" Inherits="GonzalesToolsEntertainmentForGift" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <link href="WebStyle.css" rel="stylesheet" type="text/css" />
</head>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script language="javascript" type="text/javascript">

    var IsCashClaim = true;

	function FillData() {
	
		var remarks = RequestQueryString("remarks");
		var amt = RequestQueryString("amt");
		var type = RequestQueryString("type");		
		/*
		if (remarks != "") {
			var RemarksArray = remarks.split(",");

			document.getElementById("TextBox_NoOfParticipants").value = RemarksArray[1];										
		
		    if (amt != "") {
                document.getElementById("TextBox_TotalCost").value = amt;									
		    }			
		}
		*/	
		
		if (type != "" && type == "1") {
            IsCashClaim = false;		
            document.getElementById("TextBox_TotalCost").value = amt;            							
		}			
	}
	
	function TotalOnFocus() {
	    if (!IsCashClaim) {
	       document.getElementById("TextBox_TotalCost").blur(); 
	    }
	}	
	
    function ReCalCostPerHead () {
        
        // no need to calculate if is enter by participant
        if (document.getElementById("TextBox_NoOfParticipants").value > 10){
             for (var x = 0; x < document.forms[0].elements.length; x++) {
                
                if (document.forms[0].elements[x].name.indexOf("_IsEmpty") > 0) {
                    
                    var RowID = document.forms[0].elements[x].name.substring (0, 36);
                    
                    if (document.getElementById(RowID + "TextBox_Attendees").value.length > 0 || 
                        document.getElementById(RowID + "TextBox_Title").value.length > 0 ||
                        document.getElementById(RowID + "TextBox_Company").value.length > 0) {
                            
                        document.getElementById(RowID + "_IsEmpty").value = 0;  // not empty
                        TotalAttendees++;                    
                    } else {
                        document.getElementById(RowID + "_IsEmpty").value = 1;  // is empty     
                        return;           
                    }
                }               
            }           
         }
        
        var TotalCost = parseFloat(document.getElementById("TextBox_TotalCost").value.replace(/,/g,''));
        var TotalAttendees = 0;
        
        for (var x = 0; x < document.forms[0].elements.length; x++) {
            
            if (document.forms[0].elements[x].name.indexOf("_IsEmpty") > 0) {
                
                var RowID = document.forms[0].elements[x].name.substring (0, 36);
                
                if (document.getElementById(RowID + "TextBox_Attendees").value.length > 0 || 
                    document.getElementById(RowID + "TextBox_Title").value.length > 0 ||
                    document.getElementById(RowID + "TextBox_Company").value.length > 0) {
                        
                    document.getElementById(RowID + "_IsEmpty").value = 0;  // not empty
                    TotalAttendees++;                    
                } else {
                    document.getElementById(RowID + "_IsEmpty").value = 1;  // is empty                
                }
            }               
        }   // for
        
        document.forms[0].HiddenField_TotalParticipants.value = TotalAttendees;
        
        if (TotalAttendees > 0) {
            
            var TotalCostPerHead = Round((TotalCost/TotalAttendees), 2);
        
            for (var x = 0; x < document.forms[0].elements.length; x++) {
                
                if (document.forms[0].elements[x].name.indexOf("_IsEmpty") > 0) {
                    
                    var RowID = document.forms[0].elements[x].name.substring (0, 36);
                    
                    if (document.getElementById(RowID + "_IsEmpty").value == 0) {
                            
                        document.getElementById(RowID + "TextBox_CostPerHead").value = TotalCostPerHead;                           
                    }                                               
                }               
            }   // for        
        }   
                        
        document.getElementById("TextBox_NoOfParticipants").value = TotalAttendees;   
    }
    
    function Validate() {
    
        var valid = true;
        
        if (document.forms[0].TextBox_Purpose.value.length == 0) {
            document.forms[0].TextBox_Purpose.className = "ValidatedErrorComponent";
            valid = false;
        } else {
            document.forms[0].TextBox_Purpose.className = "FormTextBox";
        }
        
        if (document.forms[0].TextBox_TotalCost.value.length == 0 ) {
            document.forms[0].TextBox_TotalCost.className = "ValidatedErrorComponent";
            valid = false;
        } else {
            document.forms[0].TextBox_TotalCost.className = "FormTextBox";
        }  
                
        if (document.forms[0].TextBox_NoOfParticipants.value == "0") {
            document.forms[0].TextBox_NoOfParticipants.className = "ValidatedErrorComponent";
            valid = false;
        } else {
            document.forms[0].TextBox_NoOfParticipants.className = "FormTextBox";
        }            
                
        for (var x = 0; x < document.forms[0].elements.length; x++) {
            
            if (document.forms[0].elements[x].name.indexOf("_IsEmpty") > 0) {
                
                var RowID = document.forms[0].elements[x].name.substring (0, 36);
                
                if (document.getElementById(RowID + "TextBox_Attendees").value.length > 0 || 
                    document.getElementById(RowID + "TextBox_Title").value.length > 0 ||
                    document.getElementById(RowID + "TextBox_Company").value.length > 0) {
                    
                    // this row not empty
                    // now check if all fill in
                    if (document.getElementById(RowID + "TextBox_Attendees").value.length == 0) {
                    
                        document.getElementById(RowID + "TextBox_Attendees").className = "ValidatedErrorComponent";
                        valid = false;                                                             
                    } else {
                        document.getElementById(RowID + "TextBox_Attendees").className = "DetailGridTextBox";
                    }                                                                                                      
                    
                    if (document.getElementById(RowID + "TextBox_Title").value.length == 0) {
                    
                        document.getElementById(RowID + "TextBox_Title").className = "ValidatedErrorComponent";
                        valid = false;                                                             
                    } else {
                        document.getElementById(RowID + "TextBox_Title").className = "DetailGridTextBox";
                    }
                    
                    if (document.getElementById(RowID + "TextBox_Company").value.length == 0) {
                    
                        document.getElementById(RowID + "TextBox_Company").className = "ValidatedErrorComponent";
                        valid = false;                                                             
                    } else {
                        document.getElementById(RowID + "TextBox_Company").className = "DetailGridTextBox";
                    }                                        
                } 
            }               
        }   // for    
        
        // check for participants        
            // if enter no of participants is checked, check if the no. is more than 10 people
           // if (document.getElementById("TextBox_NoOfParticipants").value <= 10) {
           //    alert("If the number of participants is 10 or less, you will need to enter their names in the table");
                                
           //     valid = false;              
           // }        
        
        if (!valid) {
            if(document.getElementById("TextBox_NoOfParticipants").value < 10)
                alert(WarningMessage);
            else
                alert(MandatoryMessage);
        } 
        else if (document.forms[0].TextBox_TotalCost.value < 0 ) {
            document.forms[0].TextBox_TotalCost.className = "ValidatedErrorComponent";
            valid = false;
            alert(NonNegativeMessage);
        }   
        
        return valid;
    
    }    
    
    function ValidateWithoutParticipantNo() {
    
        var valid = true;
        
        if (document.forms[0].TextBox_Purpose.value.length == 0) {
            document.forms[0].TextBox_Purpose.className = "ValidatedErrorComponent";
            valid = false;
        } else {
            document.forms[0].TextBox_Purpose.className = "FormTextBox";
        }
        
        if (document.forms[0].TextBox_TotalCost.value.length == 0) {
            document.forms[0].TextBox_TotalCost.className = "ValidatedErrorComponent";
            valid = false;
        } else {
            document.forms[0].TextBox_TotalCost.className = "FormTextBox";
        }   
        
        if (document.forms[0].TextBox_NoOfParticipants.value == "0") {
            document.forms[0].TextBox_NoOfParticipants.className = "ValidatedErrorComponent";
            valid = false;
        } else {
            document.forms[0].TextBox_NoOfParticipants.className = "FormTextBox";
        }                
        
        
        for (var x = 0; x < document.forms[0].elements.length; x++) {
            
            if (document.forms[0].elements[x].name.indexOf("_IsEmpty") > 0) {
                
                var RowID = document.forms[0].elements[x].name.substring (0, 36);
                
                if (document.getElementById(RowID + "TextBox_Attendees").value.length > 0 || 
                    document.getElementById(RowID + "TextBox_Title").value.length > 0 ||
                    document.getElementById(RowID + "TextBox_Company").value.length > 0) {
                    
                    // this row not empty
                    // now check if all fill in
                    if (document.getElementById(RowID + "TextBox_Attendees").value.length == 0) {
                    
                        document.getElementById(RowID + "TextBox_Attendees").className = "ValidatedErrorComponent";
                        valid = false;                                                             
                    } else {
                        document.getElementById(RowID + "TextBox_Attendees").className = "DetailGridTextBox";
                    }                                                                                                      
                    
                    if (document.getElementById(RowID + "TextBox_Title").value.length == 0) {
                    
                        document.getElementById(RowID + "TextBox_Title").className = "ValidatedErrorComponent";
                        valid = false;                                                             
                    } else {
                        document.getElementById(RowID + "TextBox_Title").className = "DetailGridTextBox";
                    }
                    
                    if (document.getElementById(RowID + "TextBox_Company").value.length == 0) {
                    
                        document.getElementById(RowID + "TextBox_Company").className = "ValidatedErrorComponent";
                        valid = false;                                                             
                    } else {
                        document.getElementById(RowID + "TextBox_Company").className = "DetailGridTextBox";
                    }                                        
                } 
            }               
        }   // for    
            
        if (!valid) {
            alert(MandatoryMessage);
        }    
        
        return valid;
    
    }    
    
    function SwitchOption(Obj, OpositeObj) {
        OpositeObj.checked = !Obj.checked;                       
    }
    
    function PassParameter()
	{
	    document.getElementById("hiddenClose").value = "true";
	    return true;
	}
	
	
</script>
<body>
<form id="Form1" method="post" runat="server">
  <table width="100%" border="0" cellpadding="2" cellspacing="1">
    <tr>
      <td height="40" class="PageTitle"><asp:Label ID="Label_Title" runat="server" Text='Entertainment'></asp:Label></td>
    </tr>
    <tr>
      <td><asp:Table CellPadding="5" CellSpacing="0" ID="Table_MessageBox" Width="100%" runat="server" Visible="false">
        <asp:TableRow>
          <asp:TableCell CssClass="ErrorBox" ></asp:TableCell>
        </asp:TableRow>
      </asp:Table></td>
    </tr>
    <tr>
      <td><table width="100%" border="0" cellpadding="5" cellspacing="0" class="FormBorder">
        <tr>
          <td width="170" class="FormLineItemAlt"><asp:Label CssClass="FormField" ID="Label2" runat="server" Text='Purpose:' /></td>
          <td width="50%" class="FormLineItemAlt"><asp:TextBox ID="TextBox_Purpose" runat="server"
                  CssClass="FormTextBox" MaxLength="50" Rows="50" Width="200px"></asp:TextBox></td>
        </tr>
        <tr>
          <td class="FormLineItem"><asp:Label CssClass="FormField" ID="Label_GovOfficial" runat="server" Text='Government Officials:' /></td>
          <td class="FormLineItem"><asp:CheckBox ID="CheckBox_IsGovOfficial" runat="server" /></td>
        </tr>
        <tr>
          <td class="FormLineItemAlt"><asp:Label CssClass="FormField" ID="Label_TotalCost" runat="server" Text='Total Cost:' /></td>
          <td class="FormLineItemAlt"><asp:TextBox CssClass="FormTextBox" ID="TextBox_TotalCost" runat="server" TextMode="SingleLine" /></td>
        </tr>
        <tr>
          <td class="FormLineItem" colspan="2"><asp:Label CssClass="FormField" ID="Label_Participants" runat="server" Text='Participants:' /></td>
        </tr>
        <tr>
          <td class="FormLineItem" colspan="2"><asp:Label CssClass="NormalBodyText" ID="Label_ParticipantsDesc" Width="95%" runat="server" Text='If the number of participants is <u>more than 10</u>, you have the option to attach their name list through supporting document. Just fill in the "Total number of participants" and click "Save & Exit".'  /></td>
        </tr>
        <tr>
            <td class="FormLineItem"><asp:Label ID="Label_TotalNoParticipant" runat="server" CssClass="FormField" Text = "Total number of participants:"></asp:Label>
            <asp:TextBox Columns="4" CssClass="FormTextBox" ID="TextBox_NoOfParticipants" runat="server" TextMode="SingleLine" Text='0' /></td>
            <td class="FormLineItem" align="right"><asp:Button ID="Button_SaveNExit" CssClass="FormButton" runat="server" Text ="Save & Exit" OnClick="Button_Done_Click1" /></td>

        </tr>
        <tr>
          <td class="FormLineItemAlt" colspan="2"><asp:Label CssClass="NormalBodyText" ID="Label_desc" Width="95%" runat="server" Text='For <u>10 or less</u> participants, it is <u>mandatory</u> to fill in the table below. This table can be used with any numbers of participants. Note that "Total number of participants" will automatically be calculated.'  /></td>
        </tr>
        <tr>
          <td colspan="2" class="FormLineItem"><asp:Table ID="Table_ClaimDetailGrid" runat="server" Width="100%" CellPadding="0" CellSpacing="1" CssClass="FormBorder"> </asp:Table></td>
        </tr>
                <tr>
          <td colspan="2" class="FormLineItem" align="left"><asp:Button ID="Button_Remove" runat="server" CssClass="FormButton" OnClick="Button_Remove_Click"
                  Text="Remove Selected Items" />&nbsp;<asp:Button CssClass="FormButton" ID="Button_AddMoreRow" runat="server" Text="Add More Items" OnClick="Button_AddMoreRow_Click" />&nbsp;<asp:Button ID="Button_ClearAll" runat="server" OnClick="Button_ClearAll_Click" Text="Clear All Items" CssClass="FormButton" />
              <asp:HiddenField ID="HiddenField_TotalParticipants" runat="server" />
          </td>
        </tr>
        <tr>
          <td colspan="2" class="FormLineItemAlt" align="left"><span class="FormLineItemAlt">
            <asp:Button ID="Button_PasteNameList" runat="server" CssClass="FormButton" OnClick="Button_PasteNameList_Click"
                  Text="Paste from Clipboard" Width="150px" />&nbsp;<asp:Button ID="Button_Copy" runat="server" OnClick="Button_Copy_Click" Text="Copy to Clipboard(click Save)" CssClass="FormButton" Width="210px" />&nbsp;<asp:Button ID="Button_Calculate" runat="server" CssClass="FormButton" Text="Calculate Cost per head" Width="180px" />           
          </span></td>
        </tr>

        <tr>
            <td colspan="2" class="FormLineItem" align="right"><asp:Button ID="Button_Submit" Text="Save" runat="server" CssClass="FormButton" OnClick="Button_Submit_Click" />
              <asp:Button ID="Button_Done" runat="server" CssClass="FormButton" Text="Save & Exit" OnClick="Button_Done_Click" />
              <asp:Button ID="Button_Cancel" runat="server" CssClass="FormButton" Text="Cancel" /></td>
        </tr>
      </table></td>
    </tr>
    <input name="hiddenClose" type="hidden" class="FormTextBox" id="hiddenClose" />  
  </table>
</form>
<script language="javascript" type="text/javascript">

    ReCalCostPerHead();
    FillData();    
    
</script>
</body>
</html>
